<!DOCTYPE html>
<html lang='en'>
    <head>
        <title>绚试™ MTM管理系统(服装行业量身定制)</title>
        {include file="public/meta" /}
    </head>
    <body class='contrast-red'>
        {include file="public/header" /}
        <div id='wrapper'>
            <div id='main-nav-bg'></div>
            <nav id='main-nav'>
                <div class='navigation'>
                    {:action('ShowMenu/index',['id' => '1'],'widget')}
                </div>
            </nav>
            <section id='content'>
                <div class='container'>
                    <div class='row'>
                        <div class='col-sm-12'>
                            {neq name="Think.get.msg" value=""}
                            <div  id="nonealert" class='alert alert-info alert-dismissable'>
                                <a class="close" data-dismiss="alert" href="#">&times;</a>
                                <i class='fa fa-info-circle'></i>{$Think.get.msg}
                            </div>
                            {/neq}
                            <div id="result" class='alert alert-info alert-dismissable' style="display:none;">

                            </div>      
                        </div>
                    </div>
                    {__CONTENT__}
                    {include file="public/footer" /}    
            </section>
        </div>
        <!-- / jquery [required] -->
        {include file="public/bottomjs" /}
        <script>
            var u = $(".active").parent('ul');
            var uc = u.attr("class");//
            if (uc == 'nav nav-stacked') {
                u.prev().attr("class", "dropdown-collapse in");
                u.show();
            }
        </script>
        <script type="text/javascript">

            $(function () {

                (function ($) {
                    var $form = $("#export-form"), $export = $("#export"), tables, $optimize = $("#optimize"), $repair = $("#repair");
                    $optimize.add($repair).click(function () {
                        $.post($(this).attr('url'), $form.serialize(), function (data) {
                            if (data.code) {
                                var html = '<i class=\'fa fa-info-circle\'></i> ' + data.msg;
                                $("#result").html(html).show();

                            } else {
                                var html = '<i class=\'fa fa-info-circle\'></i> ' + data.msg;
                                $("#result").html(html).show();
                            }
                        });
                        setTimeout("nonealert2()", 2000);
                        return false;
                    });

                    $export.click(function () {
                        $export.parent().children().prop('disabled', true);
                        $export.html("正在发送备份请求...");
                        $.post(
                                $form.attr("action"),
                                $form.serialize(),
                                function (data) {
                                    if (data.code) {
                                        tables = data.data.tables;
                                        $export.html(data.msg + "开始备份，请不要关闭本页面！");
                                        backup(data.data.tab);
                                        window.onbeforeunload = function () {
                                            return "正在备份数据库，请不要关闭！";
                                        };
                                    } else {
                                        var html = '<i class=\'fa fa-info-circle\'></i> ' + data.msg;
                                        $("#result").html(html).show();
                                        $export.html("立即备份");
                                        setTimeout(function () {
                                            $export.parent().children().prop('disabled', false);
                                        }, 1500);
                                    }
                                });
                        setTimeout("nonealert2()", 2000);
                        return false;
                    });

                    function backup(tab, status) {
                        status && showmsg(tab.id, "开始备份...(0%)");
                        $.get($form.attr("action"), tab, function (data) {
                            if (data.code) {
                                showmsg(tab.id, data.msg);
                                if (!$.isPlainObject(data.data.tab)) {
                                    $export.parent().children().prop('disabled', false);
                                    $export.html("备份完成，点击重新备份");
                                    window.onbeforeunload = function () {
                                        return null;
                                    };
                                    return;
                                }
                                backup(data.data.tab, tab.id !== data.data.tab.id);
                            } else {
                                var html = '<i class=\'fa fa-info-circle\'></i> ' + data.msg;
                                $("#result").html(html).show();
                                $export.html("立即备份");
                                setTimeout(function () {
                                    $export.parent().children().prop('disabled', false);
                                }, 1500);
                            }
                        });
                    }

                    function showmsg(id, msg) {
                        $form.find("input[value=" + tables[id] + "]").closest("tr").find("#info").html(msg);
                    }

                })(jQuery);
            });

        </script>
    </body>
</html>